package com.qifan.energy.activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.qifan.energy.MainActivity;
import com.qifan.energy.R;
import com.qifan.energy.global.Keys;
import com.qifan.energy.http.net.NetUtils;
import com.qifan.energy.util.IntentUtils;
import com.qifan.energy.util.SharedPreferencesUtil;
import com.qifan.energy.util.UIUtils;
import com.orhanobut.logger.Logger;

public class LaunchActivity extends AppCompatActivity {

    private View mContentView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_launch);
        mContentView = findViewById(R.id.fullscreen_content);
        hideActionBar();
    }

    @Override
    protected void onStart() {
        super.onStart();

        /* 获取本地Token信息 */
        String token = SharedPreferencesUtil.getData(Keys.TOKEN_KEY,"");
        //启动类
        UIUtils.getHandler().postDelayed(()->{
            if (TextUtils.isEmpty(token)){
                IntentUtils.startActivity(this,SignInActivity.class);
            } else {
                Logger.i("token->authorization->:",token);
                NetUtils.saveToken(token);
                IntentUtils.startActivity(this, MainActivity.class);
            }
            finish();
        },2000);

        /*ThreadUtils.runInThread(() -> {
            SystemClock.sleep(3000);
            IntentUtils.startActivity(this,MainActivity.class);
            finish();
        });*/
    }

    @Override
    protected void onResume() {
        super.onResume();

        hideActionBar();
    }

    private void hideActionBar() {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }

        if (mContentView != null){
            mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
    }
}
